Skip to content

Conversation

@molbap
Copy link
Contributor

@molbap molbap commented Oct 22, 2025

What does this PR do?

As per title. Architecturally: Llava-next used as skeleton with a modified SamModel and a modified ClipVisionModel, keeping the deepseekV2 decoder untouched (using AutoModel) and changing using config only.

  • Working config + random weights init
  • Modular draft with subconfigs (two vision configs)
  • Conversion from original checkpoint done
  • Modular model finished
  • Integration tests/OCR tests working as in original codebase
  • Make modular slimmer
  • Make processor faster
  • Complete test suite for transformers
  • Remap weights to avoid conversion / on-the-fly conversion? (cc @ArthurZucker )

Current branch is functional. You can convert the weights and run the following on your image and you'll get a nice OCR output.

import torch
from PIL import Image

from transformers import DeepseekOcrForConditionalGeneration, DeepseekOcrProcessor
from transformers import model_addition_debugger_context


processor = DeepseekOcrProcessor.from_pretrained("deepseek_ocr_converted")
model = DeepseekOcrForConditionalGeneration.from_pretrained("deepseek_ocr_converted", dtype=torch.bfloat16)

image = Image.open("handwritten_letter_small.png").convert("RGB")

conversation = [
    {
        "role": "<|User|>",
        "content": [
            {"type": "image", "path": "./handwritten_letter_small.png"},
            {"type": "text", "text": "<|grounding|>Convert the document to markdown."},
        ],
    }
]

inputs = processor.apply_chat_template(
    conversation,
    return_dict=True,
    tokenize=True,
    add_generation_prompt=True,
    return_tensors="pt"
    )

with torch.no_grad():
    generated = model.generate(**inputs, max_new_tokens=50)

text = processor.batch_decode(generated, skip_special_tokens=False)[0]
print(text.strip())

@molbap
Copy link
Contributor Author

molbap commented Oct 28, 2025

Implementation works. Processor remains to be optimized but getting similar results as in original repository.

@molbap molbap marked this pull request as ready for review October 28, 2025 18:25
@molbap molbap changed the title [WIP] add deepseek ocr Add deepseek ocr Oct 28, 2025
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto, deepseek_ocr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants